﻿using SqlSugar;
using WMS_DATABASE_MYSQL.MappingClass;
using WMS_DATABASE_MYSQL.MappingClass.CategoryClass;
using WMS_DATABASE_MYSQL.MappingClass.PropertyClass;
using WMS_DATABASE_MYSQL.MappingClass.SystemClass;

namespace WMS_DATABASE_MYSQL
{
    public class sqlsugar_create
    {
        public readonly ISqlSugarClient db;
        public sqlsugar_create(ISqlSugarClient db)
        {
            this.db = db;
        }
        public void CreateTable()
        {
            //建库 如果不存在创建数据库，存在不会重复创建
            db.DbMaintenance.CreateDatabase();
            //建表
            //先获取修改是不是符合要求，符合要求在执行更新表
            var diffStringlen = db.CodeFirst.GetDifferenceTables(
                typeof(wms_category_table), 
                typeof(wms_categoryclass_table), 
                typeof(wms_calproperty_table),
                typeof(wms_edaqproperty_table),
                typeof(wms_deptsecgrp_table),
                typeof(wms_assets_table), 
                typeof(wms_check_table),
                typeof(wms_inbound_table), 
                typeof(wms_outbound_table), 
                typeof(wms_scrap_table),
                typeof(wms_sysauthority),
                typeof(wms_syscurrentuser))
                .ToDiffString().Length;
            if (diffStringlen > 25)
            {
                db.CodeFirst.InitTables(new Type[] //支持多表创建
                {
                    typeof(wms_category_table), 
                    typeof(wms_categoryclass_table),
                    typeof(wms_calproperty_table), 
                    typeof(wms_edaqproperty_table),
                    typeof(wms_deptsecgrp_table),
                    typeof(wms_assets_table),
                    typeof(wms_check_table), 
                    typeof(wms_inbound_table), 
                    typeof(wms_outbound_table),
                    typeof(wms_scrap_table),
                    typeof(wms_sysauthority),
                    typeof(wms_syscurrentuser)
                });
            }
        }
    }
}
